package cn.dzh.service.impl;



import cn.dzh.dal.mapper.*;
import cn.dzh.model.bean.CommodityBase;
import cn.dzh.model.bean.CommodityDraft;
import cn.dzh.service.CommodityDraftService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;


/**
 * @author 聂海波
 * @version 1.1
 * @date 2023/10/24 14:34
 */
@Service
@Transactional
public class CommodityDraftServiceImpl implements CommodityDraftService {
    @Resource
    private CommodityDraftMapper commodityDraftMapper;
    @Resource
    private CommodityBaseMapper commodityBaseMapper;
    @Resource
    private ServiceTermsMapper serviceTermsMapper;
    @Resource
    private ExchangePriceMapper exchangePriceMapper;
    @Resource
    private PutInMapper putInMapper;
    @Resource
    private CommodityUserMapper commodityUserMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addToDraft(CommodityDraft commodityDraft) {
        return commodityDraftMapper.insert(commodityDraft);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateGoodsById(CommodityDraft commodityDraft) {
        int a = commodityDraftMapper.updateByPrimaryKey(commodityDraft);
        int b = commodityBaseMapper.updateBygoodsId(commodityDraft);
        int c = serviceTermsMapper.updateBygoodsId(commodityDraft);
        int d = exchangePriceMapper.updateBygoodsId(commodityDraft);
        int e = putInMapper.updateBygoodsId(commodityDraft);
        if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0) {
            return 0;
        }
        return 1;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommodityDraft findCommodityDraft(int id) {
        CommodityDraft commodityDraft = null;
        try {
            commodityDraft = commodityDraftMapper.selectById(id);
        } catch (Exception e) {
            return null;
        }
        return commodityDraft;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String selectStatus(int id) {
        String status = commodityDraftMapper.selectStatus(id);
        return status;
    }

    @Override
    @Transactional(rollbackFor = Exception.class,readOnly = true)
    public List<CommodityBase> selectBase(CommodityBase commodityBase) {
        List<CommodityBase> list= commodityBaseMapper.selectBase(commodityBase);
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class,readOnly = true)
    public List selectById(Integer id) {
        List list= commodityBaseMapper.selectById(id);
        return list;
    }
}
